import { instance } from '../request'
import { UserDataSetTypeEnum } from '@/type/enum'

const request = instance

/**
 * 获取用户角色详情
 *
 * @param userId 用户id
 * @return s
 */
export const getUserRolesDetailApi = (
  userId: string
): PromiseRes<{
  roleIdList: string[]
  roleNameList: string[]
  rolesList: RoleItf[]
}> => request.get(`/userRoles/getUserRoles/${userId}`)

/**
 * 为用户设置角色
 *
 * @param userId     用户id
 * @param type       类型（refresh, add, remove）
 * @param roleIdList 角色id 列表
 * @return s
 */
export const setUserRolesApi = (
  userId: string,
  type: UserDataSetTypeEnum,
  roleIdList: string[]
): PromiseRes =>
  request.post(
    `/userRoles/setUserRoles?userId=${userId}&type=${type}`,
    roleIdList
  )

/**
 * 获取角色用户详情
 *
 * @param roleId 角色id
 * @returns
 */
export const getRoleUsersDetailApi = (queryCondition: {
  roleId: string
  account?: string
  nickname?: string
}): PromiseRes<UserInfoItf[]> =>
  request.post(`/userRoles/getRoleUsersDetail`, queryCondition)

/**
 * 为角色设置用户
 *
 * @param roleId     角色id
 * @param userIdList 用户id 列表
 * @returns
 */
export const setRoleUsersApi = (
  roleId: string,
  type: UserDataSetTypeEnum,
  userIdList: string[]
): PromiseRes =>
  request.post(
    `/userRoles/setRoleUsers?roleId=${roleId}&type=${type}`,
    userIdList
  )
